/*********************************************************************
	Rhapsody	: 7.6
	Login		: Pawel
	Component	: DefaultComponent
	Configuration 	: DefaultConfig
	Model Element	: Engine
//!	Generated Date	: Sun, 27, Nov 2011 
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/Engine.java
*********************************************************************/

package CargoLiftSystem;

//## link itsIEngine 
import Hardware.IEngine;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.*;
//## auto_generated
import com.ibm.rational.rhapsody.animation.*;
//## auto_generated
import com.ibm.rational.rhapsody.oxf.states.*;
//## auto_generated
import com.ibm.rational.rhapsody.animcom.animMessages.*;

//----------------------------------------------------------------------------
// CargoLiftSystem/Engine.java                                                                  
//----------------------------------------------------------------------------

//## package CargoLiftSystem 


//## class Engine 
public class Engine implements RiJStateConcept, Animated {
    
    //#[ ignore
    // Instrumentation attributes (Animation)
    private Animate animate;
    
    public static AnimClass animClassEngine = new AnimClass("CargoLiftSystem.Engine",false);
    //#]
    
    public Reactive reactive;		//## ignore 
    
    protected IEngine itsIEngine;		//## link itsIEngine 
    
    protected Lift itsLift;		//## link itsLift 
    
    //#[ ignore 
    public static final int RiJNonState=0;
    public static final int Moving=1;
    public static final int MovingUp=2;
    public static final int MovingDown=3;
    public static final int Idle=4;
    //#]
    protected int rootState_subState;		//## ignore 
    
    protected int rootState_active;		//## ignore 
    
    protected int Moving_subState;		//## ignore 
    
    
    //## statechart_method 
    public RiJThread getThread() {
        return reactive.getThread();
    }
    
    //## statechart_method 
    public void schedTimeout(long delay, long tmID, RiJStateReactive reactive) {
        getThread().schedTimeout(delay, tmID, reactive);
    }
    
    //## statechart_method 
    public void unschedTimeout(long tmID, RiJStateReactive reactive) {
        getThread().unschedTimeout(tmID, reactive);
    }
    
    //## statechart_method 
    public boolean isIn(int state) {
        return reactive.isIn(state);
    }
    
    //## statechart_method 
    public boolean isCompleted(int state) {
        return reactive.isCompleted(state);
    }
    
    //## statechart_method 
    public RiJEventConsumer getEventConsumer() {
        return (RiJEventConsumer)reactive;
    }
    
    //## statechart_method 
    public void gen(RiJEvent event) {
        reactive._gen(event);
    }
    
    //## statechart_method 
    public void queueEvent(RiJEvent event) {
        reactive.queueEvent(event);
    }
    
    //## statechart_method 
    public int takeEvent(RiJEvent event) {
        return reactive.takeEvent(event);
    }
    
    // Constructors
    
    /**
     * @param lift
    */
    //## operation Engine(Lift) 
    public  Engine(final Lift lift, RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassEngine.getUserClass(),
               new ArgData[] {
                   new ArgData(Lift.class, "lift", AnimInstance.animToString(lift))
               });
        
        reactive = new Reactive(p_thread);
        //#[ operation Engine(Lift) 
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    //## auto_generated 
    public  Engine(RiJThread p_thread) {
        try {
            animInstance().notifyConstructorEntered(animClassEngine.getUserClass(),
               new ArgData[] {
               });
        
        reactive = new Reactive(p_thread);
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation startEngine() 
    public void startEngine() {
        try {
            animInstance().notifyMethodEntered("startEngine",
               new ArgData[] {
               });
        
        //#[ operation startEngine() 
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## operation stopEngine() 
    public void stopEngine() {
        try {
            animInstance().notifyMethodEntered("stopEngine",
               new ArgData[] {
               });
        
        //#[ operation stopEngine() 
        //#]
        }
        finally {
            animInstance().notifyMethodExit();
        }
        
    }
    
    //## auto_generated 
    public IEngine getItsIEngine() {
        return itsIEngine;
    }
    
    //## auto_generated 
    public void setItsIEngine(IEngine p_IEngine) {
        itsIEngine = p_IEngine;
        if(p_IEngine != null)
            {
                animInstance().notifyRelationAdded("itsIEngine", p_IEngine);
            }
        else
            {
                animInstance().notifyRelationCleared("itsIEngine");
            }
    }
    
    //## auto_generated 
    public Lift getItsLift() {
        return itsLift;
    }
    
    //## auto_generated 
    public void __setItsLift(Lift p_Lift) {
        itsLift = p_Lift;
        if(p_Lift != null)
            {
                animInstance().notifyRelationAdded("itsLift", p_Lift);
            }
        else
            {
                animInstance().notifyRelationCleared("itsLift");
            }
    }
    
    //## auto_generated 
    public void _setItsLift(Lift p_Lift) {
        if(itsLift != null)
            {
                itsLift.__setItsEngine(null);
            }
        __setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void setItsLift(Lift p_Lift) {
        if(p_Lift != null)
            {
                p_Lift._setItsEngine(this);
            }
        _setItsLift(p_Lift);
    }
    
    //## auto_generated 
    public void _clearItsLift() {
        animInstance().notifyRelationCleared("itsLift");
        itsLift = null;
    }
    
    //## auto_generated 
    public boolean startBehavior() {
        boolean done = false;
        done = reactive.startBehavior();
        return done;
    }
    
    //## ignore 
    public class Reactive extends RiJStateReactive implements AnimatedReactive {
        
        // Default constructor 
        public Reactive() {
            this(RiJMainThread.instance());
        }
        
        
        // Constructors
        
        public  Reactive(RiJThread p_thread) {
            super(p_thread);
            initStatechart();
        }
        
        //## statechart_method 
        public boolean isIn(int state) {
            if(Moving_subState == state)
                {
                    return true;
                }
            if(rootState_subState == state)
                {
                    return true;
                }
            return false;
        }
        
        //## statechart_method 
        public boolean isCompleted(int state) {
            return true;
        }
        
        //## statechart_method 
        public void rootState_add(AnimStates animStates) {
            animStates.add("ROOT");
            switch (rootState_subState) {
                case Moving:
                {
                    Moving_add(animStates);
                }
                break;
                case Idle:
                {
                    Idle_add(animStates);
                }
                break;
                default:
                    break;
            }
        }
        
        //## statechart_method 
        public void rootState_entDef() {
            {
                rootState_enter();
                rootStateEntDef();
            }
        }
        
        //## statechart_method 
        public int rootState_dispatchEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            switch (rootState_active) {
                case MovingUp:
                {
                    res = MovingUp_takeEvent(id);
                }
                break;
                case MovingDown:
                {
                    res = MovingDown_takeEvent(id);
                }
                break;
                case Idle:
                {
                    res = Idle_takeEvent(id);
                }
                break;
                default:
                    break;
            }
            return res;
        }
        
        //## statechart_method 
        public void Moving_add(AnimStates animStates) {
            animStates.add("ROOT.Moving");
            switch (Moving_subState) {
                case MovingUp:
                {
                    MovingUp_add(animStates);
                }
                break;
                case MovingDown:
                {
                    MovingDown_add(animStates);
                }
                break;
                default:
                    break;
            }
        }
        
        //## statechart_method 
        public void MovingUp_add(AnimStates animStates) {
            animStates.add("ROOT.Moving.MovingUp");
        }
        
        //## statechart_method 
        public void MovingDown_add(AnimStates animStates) {
            animStates.add("ROOT.Moving.MovingDown");
        }
        
        //## statechart_method 
        public void Idle_add(AnimStates animStates) {
            animStates.add("ROOT.Idle");
        }
        
        //## auto_generated 
        protected void initStatechart() {
            rootState_subState = RiJNonState;
            rootState_active = RiJNonState;
            Moving_subState = RiJNonState;
        }
        
        //## statechart_method 
        public void MovingDownEnter() {
        }
        
        //## statechart_method 
        public void MovingUp_entDef() {
            MovingUp_enter();
        }
        
        //## statechart_method 
        public void Moving_enter() {
            animInstance().notifyStateEntered("ROOT.Moving");
            rootState_subState = Moving;
            MovingEnter();
        }
        
        //## statechart_method 
        public void MovingDown_exit() {
            MovingDownExit();
            animInstance().notifyStateExited("ROOT.Moving.MovingDown");
        }
        
        //## statechart_method 
        public void MovingDownExit() {
        }
        
        //## statechart_method 
        public void MovingUpEnter() {
        }
        
        //## statechart_method 
        public int Idle_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(evMove.evMove_CargoLiftSystem_id))
                {
                    res = IdleTakeevMove();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void Idle_enter() {
            animInstance().notifyStateEntered("ROOT.Idle");
            rootState_subState = Idle;
            rootState_active = Idle;
            IdleEnter();
        }
        
        //## statechart_method 
        public int MovingDown_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            res = Moving_takeEvent(id);
            return res;
        }
        
        //## statechart_method 
        public void MovingUp_exit() {
            MovingUpExit();
            animInstance().notifyStateExited("ROOT.Moving.MovingUp");
        }
        
        //## statechart_method 
        public int MovingTakeevStopEngine() {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            animInstance().notifyTransitionStarted("1");
            Moving_exit();
            //#[ transition 1 
            itsIEngine.stopEngine();
            //#]
            Idle_entDef();
            animInstance().notifyTransitionEnded("1");
            res = RiJStateReactive.TAKE_EVENT_COMPLETE;
            return res;
        }
        
        //## statechart_method 
        public int rootState_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            return res;
        }
        
        //## statechart_method 
        public void IdleExit() {
        }
        
        //## statechart_method 
        public void Idle_entDef() {
            Idle_enter();
        }
        
        //## statechart_method 
        public int Moving_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            if(event.isTypeOf(evStopEngine.evStopEngine_CargoLiftSystem_id))
                {
                    res = MovingTakeevStopEngine();
                }
            
            return res;
        }
        
        //## statechart_method 
        public void rootState_enter() {
            animInstance().notifyStateEntered("ROOT");
            rootStateEnter();
        }
        
        //## statechart_method 
        public void rootStateEnter() {
        }
        
        //## statechart_method 
        public void MovingDown_enter() {
            animInstance().notifyStateEntered("ROOT.Moving.MovingDown");
            Moving_subState = MovingDown;
            rootState_active = MovingDown;
            MovingDownEnter();
        }
        
        //## statechart_method 
        public void MovingDown_entDef() {
            MovingDown_enter();
        }
        
        //## statechart_method 
        public int MovingUp_takeEvent(short id) {
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            res = Moving_takeEvent(id);
            return res;
        }
        
        //## statechart_method 
        public void IdleEnter() {
        }
        
        //## statechart_method 
        public void MovingUp_enter() {
            animInstance().notifyStateEntered("ROOT.Moving.MovingUp");
            Moving_subState = MovingUp;
            rootState_active = MovingUp;
            MovingUpEnter();
        }
        
        //## statechart_method 
        public void rootStateEntDef() {
            animInstance().notifyTransitionStarted("2");
            Moving_entDef();
            animInstance().notifyTransitionEnded("2");
        }
        
        //## statechart_method 
        public void MovingExit() {
        }
        
        //## statechart_method 
        public void MovingEnter() {
        }
        
        //## statechart_method 
        public void Idle_exit() {
            IdleExit();
            animInstance().notifyStateExited("ROOT.Idle");
        }
        
        //## statechart_method 
        public void MovingUpExit() {
        }
        
        //## statechart_method 
        public void Moving_entDef() {
            Moving_enter();
            
            animInstance().notifyTransitionStarted("0");
            MovingDown_entDef();
            animInstance().notifyTransitionEnded("0");
        }
        
        //## statechart_method 
        public int IdleTakeevMove() {
            evMove params = (evMove) event;
            int res = RiJStateReactive.TAKE_EVENT_NOT_CONSUMED;
            //## transition 4 
            if(params.direction == true)
                {
                    animInstance().notifyTransitionStarted("3");
                    animInstance().notifyTransitionStarted("4");
                    Idle_exit();
                    Moving_enter();
                    MovingUp_entDef();
                    animInstance().notifyTransitionEnded("4");
                    animInstance().notifyTransitionEnded("3");
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            else
                {
                    animInstance().notifyTransitionStarted("3");
                    animInstance().notifyTransitionStarted("5");
                    Idle_exit();
                    Moving_enter();
                    MovingDown_entDef();
                    animInstance().notifyTransitionEnded("5");
                    animInstance().notifyTransitionEnded("3");
                    res = RiJStateReactive.TAKE_EVENT_COMPLETE;
                }
            return res;
        }
        
        //## statechart_method 
        public void rootStateExit() {
        }
        
        //## statechart_method 
        public void Moving_exit() {
            switch (Moving_subState) {
                case MovingUp:
                {
                    MovingUp_exit();
                }
                break;
                case MovingDown:
                {
                    MovingDown_exit();
                }
                break;
                default:
                    break;
            }
            Moving_subState = RiJNonState;
            MovingExit();
            animInstance().notifyStateExited("ROOT.Moving");
        }
        
        /**  methods added just for design level debugging instrumentation */
        public boolean startBehavior() {
            try {
              animInstance().notifyBehavioralMethodEntered("startBehavior",
                  new ArgData[] {
                   });
              return super.startBehavior();
            }
            finally {
              animInstance().notifyMethodExit();
            }
        }
        public int takeEvent(RiJEvent event) { 
            try { 
              //animInstance().notifyTakeEvent(new AnimEvent(event));
              animInstance().notifyBehavioralMethodEntered("takeEvent",
                  new ArgData[] { new ArgData(RiJEvent.class, "event", event.toString())
                   });
              return super.takeEvent(event); 
            }
            finally { 
              animInstance().notifyMethodExit();
            }
        }
        /**  see com.ibm.rational.rhapsody.animation.AnimatedReactive interface */
        public AnimInstance animInstance() { 
            return Engine.this.animInstance(); 
        }
        
    }
    //#[ ignore
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimClass getAnimClass() { 
        return animClassEngine; 
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public Object getFieldValue(java.lang.reflect.Field f, Object userInstance) { 
         Object obj = null;
         try {
             obj = f.get(userInstance);
         } catch(Exception e) {
              System.err.println("Exception: getting Field value: " + e);
              e.printStackTrace();
         }
         return obj;
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public AnimInstance animInstance() {
        if (animate == null) 
            animate = new Animate(); 
        return animate; 
    } 
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addAttributes(AnimAttributes msg) {
        
    }
    /**  see com.ibm.rational.rhapsody.animation.Animated interface */
    public void addRelations(AnimRelations msg) {
        
        msg.add("itsLift", false, true, itsLift);
        msg.add("itsIEngine", false, true, itsIEngine);
    }
    /** An inner class added as instrumentation for animation */
    public class Animate extends AnimInstance { 
        public  Animate() { 
            super(Engine.this); 
        } 
        public void addAttributes(AnimAttributes msg) {
            Engine.this.addAttributes(msg);
        }
        public void addRelations(AnimRelations msg) {
            Engine.this.addRelations(msg);
        }
        
        public void addStates(AnimStates msg) {
            if ((reactive != null) && (reactive.isTerminated() == false))
              reactive.rootState_add(msg);
        }
        
    } 
    //#]
    
}
/*********************************************************************
	File Path	: DefaultComponent/DefaultConfig/CargoLiftSystem/Engine.java
*********************************************************************/

